package com.hellomaker.redismq.starter.config.parser;

import com.hellomaker.redismq.starter.config.ListenerAnnotationParser;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xianzhikun
 * @version 1.0.1
 * the parse for delegate
 */
public class DelegateListenerAnnotationParser implements ListenerAnnotationParser {

    List<ListenerAnnotationParser> parsers;

    @Override
    public void parseBean(Class<?> aClass, Object bean, String beanName) {
        if (parsers != null) {
            parsers.forEach(listenerAnnotationParser -> listenerAnnotationParser.parseBean(aClass, bean, beanName));
        }
    }

    public boolean applyParser(ListenerAnnotationParser listenerAnnotationParser) {
        if (parsers == null) {
            parsers = new ArrayList<>();
        }
        if (parsers.contains(listenerAnnotationParser)) {
            return false;
        } else {
            parsers.add(listenerAnnotationParser);
            return true;
        }
    }

}
